<template>
    <div class="layer-switcher">
        <div v-for="layer in layers" :key="layer.title" class="layer-option"
            :class="{ active: activeLayer === layer.title }" @click="onLayerChange(layer)">
            <img :src="layer.icon" alt="" class="layer-icon" />
            <span>{{ layer.title }}</span>
        </div>
    </div>
</template>

<script>
import { MapPaths } from "../../config";
import OpenLayersMap from "../../OpenLayersMap";
import { ref } from 'vue';

export default {
    name: 'LayerSwitcher',

    setup(props) {
        let olService = OpenLayersMap.getInstance()
        const layers = ref(MapPaths)
        const activeLayer = ref(layers.value[0].title);

        const onLayerChange = (layer) => {
            activeLayer.value = layer.title;
            olService.changeBaseMap(layer.key)
        };

        return {
            layers,
            activeLayer,
            onLayerChange,
        };
    },
};
</script>

<style scoped>
.layer-switcher {
    display: flex;
    flex-direction: column;
    margin: 10px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    padding: 10px;
}

.layer-option {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.layer-option:hover {
    background-color: rgba(0, 123, 255, 0.1);
}

.layer-option.active {
    background-color: #007bff;
    color: white;
}

.layer-icon {
    width: 30px;
    height: 30px;
    margin-right: 10px;
    transition: transform 0.3s;
}

.layer-option.active .layer-icon {
    transform: scale(1.1);
}
</style>